package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsNuclearDto;
import com.sale.goods.domain.vo.GoodsNuclearVo;
import com.sale.goods.service.IGoodsNuclearService;
import com.sale.goods.service.IGoodsNuclearService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 核销单
 * @Date 23-08-14
 * @Author hl
 **/

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nuclear")
public class GoodsNuclearController extends BaseController {

    private final IGoodsNuclearService goodsNuclearService;

    /**
     * 获取核销单
     */
    //@SaCheckPermission("finance:writeOff:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsNuclearDto> list(GoodsNuclearVo goodsNuclearVo, PageQuery pageQuery)
    {
        return goodsNuclearService.selectNuclearList(goodsNuclearVo,pageQuery);
    }

    /**
     * 新增核销单
     */
    //@SaCheckPermission("finance:writeOff:add")
    @Log(title = "核销单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsNuclearVo goodsNuclearVo) throws Exception {
        return toAjax(goodsNuclearService.insertNuclear(goodsNuclearVo));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("finance:writeOff:query")
    @GetMapping(value = "/{NuclearId}")
    public R getInfo(@PathVariable long NuclearId)
    {
        return R.ok(goodsNuclearService.selectNuclearById(NuclearId));
    }

    /**
     * 修改核销单
     */
    //@SaCheckPermission("finance:writeOff:edit")
    @Log(title = "核销单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsNuclearVo goodsNuclearVo) {
        return toAjax(goodsNuclearService.updateNuclearEdit(goodsNuclearVo));
    }

    /**
     * 删除核销单
     */
    //@SaCheckPermission("finance:writeOff:remove")
    @Log(title = "核销单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{NuclearId}")
    public R<Void> remove(@PathVariable("NuclearId") Long NuclearId) {
        return toAjax(goodsNuclearService.deleteNuclearById(NuclearId));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:writeOff:subExamine")
    @Log(title = "核销单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{NuclearId}")
    public R<Void> submitReview(@PathVariable("NuclearId") Long NuclearId) {
        return toAjax(goodsNuclearService.submitReview(NuclearId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:writeOff:revoke")
    @Log(title = "核销单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{NuclearId}")
    public R<Void> deleteReview(@PathVariable("NuclearId") Long NuclearId) {
        return toAjax(goodsNuclearService.deleteReview(NuclearId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:writeOff:examine")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsNuclearVo goodsNuclearVo) throws Exception {
        return toAjax(goodsNuclearService.goodSExamineReview(goodsNuclearVo));
    }

}
